package com.hn.vue.verify;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * hanni
 * 2019/3/7 0007
 * 11:00
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private ImageCodeGenerator imageCodeGenerator;

    @GetMapping("/image")
    public void imgcode(HttpServletResponse response, HttpSession session) throws IOException {

        ImageCode imageCode = imageCodeGenerator.generatorImageCode();
        BufferedImage image = imageCode.getImage();
        ImageIO.write(image,"jpeg",response.getOutputStream());//向前台展示图片
        session.setAttribute("IMAGE_CODE",imageCode);//将图片验证码保存起来，用于后续的认证


    }

}
